<template>
  <div>
    <van-dialog
      v-model="show"
      :title="title"
      :show-cancel-button="asd"
      :showConfirmButton="showConfirmButton"
      closeOnClickOverlay
    >
      <div class="content">全面保护您的隐私，关注后第一时间获取户型/朝向/优惠政策等信息。</div>
      <input class="inp" type="text" v-model="inpVal" placeholder="保护您的真实手机号码" />
      <div class="http">
        我已阅读并同意
        <span style="color:#41A107">《用户服务协议》</span>
      </div>
      <div class="subBtn" @click="subBtn">确定</div>
      <div class="footer" @click="call">
        <van-icon name="phone" size="22px" color="#48BF01" />
        <div>直拨购房团</div>
      </div>
    </van-dialog>
  </div>
</template>

<script>
import { Dialog } from "vant";
import * as API from "@/http/common/api";

import { mapState, mapMutations, mapActions } from "vuex";
export default {
  name: "dialogg",
  data() {
    return {
      show: false,
      asd: false,
      showConfirmButton: false,
      inpVal: ""
    };
  },
  props: ["groupBuyingName", "title",'name'],
  methods: {
    subBtn() {
      if (!this.inpVal) {
        this.$toast({ message: "请输入手机号" });
        return;
      }
      if (!this.isLegal(this.inpVal)) {
        this.$toast({ message: "手机号有误" });
        return;
      }
      console.log(1111111111)
      this.$http(API.addClient, {
        type: "POST",
        params: {
          clientGjProject:this.name?this.name:'',
          clientName: "",
          clientTel: this.inpVal,
          groupBuyingName: this.groupBuyingName
        }
      }).then(res => {
        if (res.data.code == 0) {
          this.$toast({ message: "提交成功" });
          this.hasOpen(); //关闭弹窗
        }
      });
    },
    //开关
    hasOpen() {
      this.show = !this.show;
    },
    //打电话
    call() {
      console.log(this.groupMobile)
      window.location.href = "tel://"+this.groupMobile;
    },
    // 手机号
    isLegal() {
      var myreg = /^(((13[0-9]{1})|(14[0-9]{1})|(15[0-9]{1})|(16[0-9]{1})|(19[0-9]{1})|(18[0-9]{1})|(17[0-9]{1}))+\d{8})$/;
      if (!myreg.test(this.inpVal)) {
        return false;
      } else {
        return true;
      }
    }
  },
  mounted() {},
  computed: {
    ...mapState({
      groupMobile: state => state.locCity.groupMobile
    })
  },
  components: {
    [Dialog.Component.name]: Dialog.Component
  }
};
</script>

<style scoped >
.van-dialog {
  font-size: 28px;
  width: 580px;
  height: 537px;
  padding: 1px 41px 1px 41px;
  box-sizing: border-box;
  border-radius: 28px;
}

.content {
  color: #999;
  line-height: 50px;
  margin-top: 20px;
}
.inp {
  width: 502px;
  height: 50px;
  background: #fff;
  border-radius: 4px;
  border: 2px solid #999999;
  text-align: center;
  margin-top: 30px;
}
.http {
  color: #666;
  text-align: center;
  margin-top: 20px;
}
.subBtn {
  width: 502px;
  height: 60px;
  background: #48bf01;
  font-size: 34px;
  color: #fff;
  text-align: center;
  line-height: 60px;
  border-radius: 5px;
  margin-top: 46px;
}
.footer {
  display: flex;
  align-items: center;
  margin-top: 20px;
  justify-content: center;
  color: #48bf01;
}
</style>
